from django.db import models


# Create your models here.
class MyUser(models.Model):
    """
    用户列表
    """
    name = models.CharField(max_length=20)
    username = models.CharField(max_length=20, unique=True)
    password = models.CharField(max_length=20)
    sex = models.IntegerField()

    class Meta:
        db_table = "MyUser"


class TaskModel(models.Model):
    """
    任务列表
    """
    name = models.CharField(max_length=20, unique=True)
    type_spider = models.CharField(max_length=20)
    type_template = models.CharField(max_length=20)
    type_business = models.CharField(max_length=20)
    proxy = models.CharField(max_length=20, null=True, blank=True)
    website = models.CharField(max_length=200, null=True, blank=True)
    xpath = models.TextField(null=True, blank=True)
    myTr = models.CharField(max_length=200, null=True, blank=True)
    myTd = models.TextField(null=True, blank=True)
    desc = models.TextField(null=True, blank=True)
    frontUrl = models.TextField(null=True, blank=True)
    backUrl = models.TextField(null=True, blank=True)
    startNum = models.IntegerField(null=True, blank=True)
    endNum = models.IntegerField(null=True, blank=True)
    myIncrease = models.IntegerField(null=True, blank=True)
    keyword = models.CharField(max_length=200, null=True, blank=True)

    class Meta:
        db_table = "TaskModel"


class TaskList(models.Model):
    """
    任务执行记录
    """
    task = models.ForeignKey(TaskModel, related_name='tracks')
    name = models.CharField(max_length=20)
    type_spider = models.CharField(max_length=20)
    type_template = models.CharField(max_length=20)
    type_business = models.CharField(max_length=20)
    jid = models.CharField(max_length=100)
    startTime = models.CharField(max_length=200, null=True, blank=True)
    endTime = models.CharField(max_length=200, null=True, blank=True)
    status = models.CharField(max_length=40, null=True, blank=True)
    downloadURL = models.CharField(max_length=200, null=True, blank=True)

    class Meta:
        db_table = "TaskList"


class jobRecord(models.Model):  # TODO：手动有操作时刷入开始结束时间
    """
    任务详情
    """
    jid = models.CharField(max_length=30)

    class Meta:
        db_table = "jobRecord"


class downlandRecord(models.Model):  # TODO：finish后 刷入数据
    """
    下载列表
    """
    jid = models.CharField(max_length=30)
    URL = models.CharField(max_length=100)

    class Meta:
        db_table = "downlandRecord"
